package pers.books.serviceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import pers.books.dao.AuthorDao;
import pers.books.entity.Author;
import pers.books.service.AuthorService;
import pers.books.util.ResultMessage;

/**
 * 
 * AuthorServiceImpl
 *
 * @author 姜治昊
 * @time 2018年5月5日 下午9:43:51
 */
@Service
public class AuthorServiceImpl implements AuthorService {

	@Autowired
	private AuthorDao authorDao;
	
	/**
	 * 根据ID获取作者
	 */
	public ResultMessage<Author> getAuthorById(String id) {
		Author author = authorDao.getAuthorById(id);
		return ResultMessage.createSuccessResultMessage(author);
	}
	
	/**
	 * 模糊查询图书
	 */
	@Override
	public Map<String, Object> getAuthors(String name, String nationality, int limit, int offset) {
		// TODO Auto-generated method stub
		Map<String, Object> result = new HashMap<>();
		List<Author> authors = authorDao.getAuthors(name, nationality, offset, limit);
		int total = authorDao.getAuthorsCount(name, nationality);
		result.put("total", total);
		result.put("rows", authors);
		return result;
	}
	
	
	@Override
	public ResultMessage<?> getAllAuthors(String nameLike, int page, int rows) {
		// TODO Auto-generated method stub
		List<Author> authors = authorDao.getAllAuthors(nameLike, page, rows);
		return ResultMessage.createSuccessResultMessage(authors);
	}

}
